package com.gongpingjialoan.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.car.SecondDetailFragment;

/**
 * Created by Administrator on 2016/5/25.
 */
public class PhonePopup extends PopupWindow implements View.OnClickListener{

    private Context mContext;

    private SecondDetailFragment mFragment;

    private View mView, main, main1;


    private ImageView close;

    private TextView mButton ,cancle;


    public PhonePopup(Fragment fragment) {
        super(fragment.getActivity());
        mFragment = (SecondDetailFragment) fragment;
        this.mContext = fragment.getActivity();
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mView = inflater.inflate(R.layout.phone_layout, null);

        this.setContentView(mView);
        main = mView.findViewById(R.id.main);
        main1 = mView.findViewById(R.id.main1);
        close = (ImageView) mView.findViewById(R.id.close);
        mButton = (TextView) mView.findViewById(R.id.sure);
        cancle = (TextView) mView.findViewById(R.id.cancle);


        close.setOnClickListener(this);
        mButton.setOnClickListener(this);
        main.setOnClickListener(this);
        main1.setOnClickListener(this);
        cancle.setOnClickListener(this);
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable cd = new ColorDrawable(0x000000);
        this.setBackgroundDrawable(cd);
    }

    @Override
    public void onClick(View v) {
        if (v == close || v == main || v == cancle) {
            dismiss();
        }else if(v == mButton){
            dismiss();
            mFragment.phone();
        }
    }
}
